package utils

import (
	"github.com/gin-gonic/gin"
	"github.com/wonderivan/logger"
	"net/http"
)

const Cookie_Name = "cookie_user"
const Cookie_Time_Length = 10 * 60

func CookieAuth(ctx *gin.Context) (*http.Cookie, error) {
	cookie, err := ctx.Request.Cookie(Cookie_Name)
	if err != nil {
		logger.Error(err.Error())
	}
	if cookie != nil {
		ctx.SetCookie(cookie.Name, cookie.Value, cookie.MaxAge, cookie.Path, cookie.Domain, cookie.Secure, cookie.HttpOnly)
	} else {
		return nil, err
	}

	return cookie, err

}
